<?php
use p5\objects\DBUtils ;

function get_sql_safe_replaced($argName)
{
    return DBUtils::get_sql_safe_replaced($argName);
}

function sql_safe_replace($value)
{
    return DBUtils::sql_safe_replace($value);
}

function db_query($sqlstr, $db_id = "default", $return_last_id = false)
{
    return DBUtils::db_query($sqlstr, $db_id, $return_last_id);
}

function do_query($sqlstr, $db_id = "default", $return_last_id = false)
{
    return DBUtils::do_query($sqlstr, $db_id, $return_last_id);
}

function batch_query($querys, $db_id = "default", $return_last_id = false)
{
    return DBUtils::batch_query($querys, $db_id, $return_last_id);
}

function batch_query_in_pdo($querys, $db_id = "default", $return_last_id = false)
{
    return DBUtils::batch_query_in_pdo($querys, $db_id, $return_last_id);
}

function db_insert($querys, $db_id = "default")
{
    return DBUtils::db_insert($querys, $db_id);
}

function quick_delete($table, $limit)
{
    return DBUtils::quick_delete($table, $limit);
}

//返回sql语句运行后影响的行数
function get_affected_query($sqlstr, $db_id = "default")
{
    return DBUtils::get_affected_query($sqlstr, $db_id);
}

function query_first_row($sqlstr, $db_id = "default")
{
    return DBUtils::query_first_row($sqlstr, $db_id);
}

function query_first_col($sqlstr, $db_id = "default")
{
    return DBUtils::query_first_col($sqlstr, $db_id);
}

function query_into_hash($sqlstr, $db_id = "default")
{
    return DBUtils::query_into_hash($sqlstr, $db_id);
}

function result_into_hash($matrix, $keyColumnName = "", $valueColumnName = "")
{
    return DBUtils::result_into_hash($matrix, $keyColumnName, $valueColumnName);
}

function query_into_map($sqlstr, $db_id = "default")
{
    return DBUtils::query_into_map($sqlstr, $db_id);
}

function result_to_map($matrix)
{
    return DBUtils::result_to_map($matrix);
}

function query_result($sqlstr, $db_id = "default", $resultType = 'MYSQL_ASSOC')
{
    return DBUtils::query_result($sqlstr, $db_id, $resultType);
}


function query_result_in_pdo($sqlstr, $db_id = "default", $resultType = 'MYSQL_ASSOC')
{
    return DBUtils::query_result_in_pdo($sqlstr, $db_id, $resultType);
}

function query_with_group_by($sqlstr, $keyColumn, $db_id = "default")
{
    return DBUtils::query_with_group_by($sqlstr, $keyColumn, $db_id);
}

function query_col00($sql, $db_id = "default")
{
    return DBUtils::query_col00($sql, $db_id);
}

function column_into_list($result, $column = "", $distinct = false)
{
    return DBUtils::column_into_list($result, $column, $distinct);
}

function find_line($result, $key, $value)
{
    return DBUtils::find_line($result, $key, $value);
}

function pdo_support()
{
    return DBUtils::pdo_support();
}

/**
 * @author huangping
 * @name db_insert
 * @param $sql insert 语句
 * @param $db_id 数据库id
 * @return 失败返回null 否则返回自增ID值
 * @commit 当前函数 @mysql_connect 已经不被5.5支持，仅能使用pdo模式
 *
 * function db_insert($sqlstr,$db_id="default")
 * {
 * global $dbs;
 * $db_id = empty($db_id) ? "default" : $db_id ;
 *
 * if(pdo_support()){
 * return db_insert_in_pdo($sqlstr,$db_id);
 * }
 * $link = @mysql_connect($dbs[$db_id]["host"],$dbs[$db_id]["user"],$dbs[$db_id]["pass"]);
 * mysql_query("SET NAMES '".$dbs[$db_id]["mysql_encoding"]."'");
 * mysql_select_db($dbs[$db_id]["db_name"],$link);
 * $result = mysql_query($sqlstr,$link);
 * $last_id = null;
 * if($result)
 * {
 * $last_id = mysql_insert_id();
 * }
 * unset($result);
 * mysql_close($link);
 * return $last_id;
 * }
 * @author huangping
 * @name db_insert_in_pdo
 * @param $sql insert 语句
 * @param $db_id 数据库id
 * @return 失败返回null 否则返回自增ID值
 *
 * function db_insert_in_pdo($sqlstr,$db_id="default")
 * {
 * global $dbs;
 * $db_id = empty($db_id) ? "default" : $db_id ;
 * $matrix = array() ;
 * $dsn = "mysql:host=".$dbs[$db_id]["host"].";dbname=".$dbs[$db_id]["db_name"];
 * $db = new PDO($dsn, $dbs[$db_id]["user"], $dbs[$db_id]["pass"],array(PDO::ATTR_PERSISTENT => true));
 * $db->exec("SET NAMES '".$dbs[$db_id]["mysql_encoding"]."'");
 * $rs = $db->query($sqlstr);
 * $last_id = null;
 * if($rs)
 * {
 * $last_id = $db->lastInsertId();
 * }
 * unset($rs);
 * return $last_id;
 * }
 */
